<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" layout:decorator="layout/default">
<head>
    <meta charset="UTF-8">
    <title>用户列表</title>
</head>
<section layout:fragment="content">
    <div class="layui-fluid">
        <div class="layui-collapse" lay-accordion>
            <div class="layui-colla-item">
                <h2 class="layui-colla-title search-colla-title"><i
                        class="icon iconfont icon-circle"></i><span>查询条件</span></h2>
                <div class="layui-colla-content layui-show">
                    <form id="searchUserForm" class="layui-form" action="" autocomplete="off">
                        <input type="hidden" class="layui-input eyc-uppercase" name="userType" th:value="${userType}">
                        <div class="layui-row layui-col-space30">
                            <div class="layui-col-sm3">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">用户ID</label>
                                    <input class="layui-input eyc-uppercase" name="userId" type="text">
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-row layui-col-space15">
                                    <div class="layui-col-sm6">
                                        <label class="layui-form-label">下单日期从</label>
                                        <input type="text" class="layui-input">
                                    </div>
                                    <div class="layui-col-sm6">
                                        <label class="layui-form-label">到</label>
                                        <input type="text" class="layui-input">
                                    </div>
                                </div>

                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">客户</label>
                                    <input class="layui-input eyc-uppercase" name="csoNum" type="text">
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">&nbsp;</label>
                                    <div class="layui-row">
                                        <button type="button" data-method="search"
                                                class="layui-btn layui-btn-sm layui-btn-primary layui-border-green">
                                            <i class="icon iconfont icon-search"></i>查询
                                        </button>
                                        <button type="button" data-method="reset"
                                                class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue">
                                            <i class="icon iconfont icon-reset"></i><span>重置</span>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-form-item eyc-margin-top15">
                <label class="layui-colla-title"><i class="icon iconfont icon-circle"></i><span>客户列表</span></label>
            </div>
            <div id="userList"></div>
        </div>
    </div>
    <script th:inline="javascript">
        var userType =/*[[${userType}]]*/ 'OUTER_USER';
    </script>
    <script th:src="@{/layui/layui.js}"></script>
    <script>
        var user = {
            $table: $('#userList')
        };
        var calcTableHeight = ($tableContainer) => {
            var paddingTop = $('body').css('padding-top');
            var bodyPaddingHeight = paddingTop.replace(/[^0-9]/ig, "");
            var height = $(window).height() - $tableContainer.offset().top - $(window).scrollTop() - bodyPaddingHeight;
            return height;
        };
        var initTable = () => {
            let colModel = [
                {
                    align: "center",
                    cb: {header: true, select: true, all: false},
                    type: 'checkbox',
                    dataType: 'bool',
                    editor: false,
                    sortable: false,
                    minWidth: 50,
                    width: 50
                }
                , {
                    dataIndx: 'userId',
                    title: userType === 'OUTER_USER' ? '客户Id' : '用户Id',
                    editable: false,
                    align: "center",
                    minWidth: 100
                }
                , {dataIndx: 'nickName', title: '昵称', editable: false, align: "center", minWidth: 100}
                , {dataIndx: 'phoneNumber', title: '手机号', editable: false, align: "center", minWidth: 180}
                , {
                    dataIndx: 'gender',
                    title: '性别',
                    editable: false,
                    align: "center",
                    minWidth: 100,
                    render: function (ui) {
                        if (ui.cellData) {
                            return '男';
                        }
                        return '女';
                    }
                }
                , {dataIndx: 'grand', title: '客户等级', editable: false, align: "center", minWidth: 120}
                , {
                    dataIndx: 'isActive',
                    title: '客户等级',
                    editable: false,
                    align: "center",
                    minWidth: 120,
                    render: function (ui) {
                        if (!ui.cellData) {
                            return '无效';
                        }
                        return '有效';
                    }
                }
            ];

            let option = {
                width: '100%',
                dataModel: {
                    recIndx: "userId",
                    contentType: "application/json;charset=UTF-8",
                    location: "remote",
                    dataType: "JSON",
                    method: "POST",
                    url: "/eyc/searchUsers",
                    postData: eyc.pqGrid.searchParam,
                    getData: eyc.pqGrid.dataResponse,
                    error: eyc.ajax.ajaxError
                },
                pageModel: {
                    type: "remote",
                    rPP: 50,
                    curPage: 1,
                    rPPOptions: [50, 100, 200]
                },
                sortModel: {
                    type: 'remote',
                    single: true
                },
                colModel: colModel,
                searchFormId: "#searchUserForm",
                scrollModel: {autoFit: false},
                showTop: false,
                numberCell: {show: false},
                virtualX: false,
                virtualY: true,
                wrap: false,
                height: calcTableHeight(user.$table),
                selectionModel: {type: 'cell',/*toggle: true,*/ mode: "single"}
            };
            eyc.pqGrid.init(user.$table, option);
        };
        layui.use(['layer', 'form'], function () {
            var layer = layui.layer
                , form = layui.form;
            initTable();
        });
    </script>
</section>
</html>